#ifndef  RECOVERY_FS_FILE_FILEAPPENDER_H
#define  RECOVERY_FS_FILE_FILEAPPENDER_H

#include <string>
#include <memory>
#include "recovery/fs/file/AbstractFileOperation.h"

namespace recovery {
namespace fs {
namespace file {


class FileAppender : public AbstractFileOperation{
public:

    static ErrnoStatus openExist(const std::string & path, std::unique_ptr<FileAppender> & appender);
    static ErrnoStatus create(const std::string & path, std::unique_ptr<FileAppender> & appender);

    ~FileAppender() override {}

    ErrnoStatus append(const char * buf, const size_t len, size_t & appendedBytes);
    ErrnoStatus append(const std::string & data, size_t & appendedBytes);
    ErrnoStatus sync();
protected:
    ErrnoStatus closeOnce() override;
private:
    explicit FileAppender(const std::string & path);
};

} //end of namespace file
} //end of namespace fs
} //end of namespace recovery


#endif   /* RECOVERY_FS_FILE_FILEAPPENDER_H */
